To be able to edit code and run cells, you need to run the notebook yourself. Where would you like to run the notebook?

In the cloud (experimental)

Binder is a free, open source service that runs scientific notebooks in the cloud! It will take a while, usually 2-7 minutes to get a session.

On your computer

(Recommended if you want to store your changes.)

  1. Copy the notebook URL:
  2. Run Pluto

    (Also see: How to install Julia and Pluto)

  3. Paste URL in the Open box

Frontmatter

If you are publishing this notebook on the web, you can set the parameters below to provide HTML metadata. This is useful for search engines and social media.

Author 1
👀 Reading hidden code
using Pkg
285 μs
👀 Reading hidden code
Pkg.activate()
❔
  Activating project at `~/.julia/environments/v1.7`
153 ms
Error message

The package AbstractPlutoDingetjes.jl could not load because it failed to initialize.

That's not nice! Things you could try:

  • Restart the notebook.
  • Try a different Julia version.
  • Contact the developers of AbstractPlutoDingetjes.jl about this error.

You might find useful information in the package installation log:

👀 Reading hidden code
using AbstractPlutoDingetjes
---
Error message

The package AbstractPlutoDingetjes.jl could not load because it failed to initialize.

That's not nice! Things you could try:

  • Restart the notebook.
  • Try a different Julia version.
  • Contact the developers of AbstractPlutoDingetjes.jl about this error.

You might find useful information in the package installation log:

this suckz 💣
import AbstractPlutoDingetjes.Bonds.with_js_link
👀 Reading hidden code
---
Error message

The package HypertextLiteral.jl could not load because it failed to initialize.

That's not nice! Things you could try:

  • Restart the notebook.
  • Try a different Julia version.
  • Contact the developers of HypertextLiteral.jl about this error.

You might find useful information in the package installation log:

using HypertextLiteral
👀 Reading hidden code
---
# let
# messages_to_js = Channel()
# send_to_js(msg) = put!(messages_to_js, msg)


# function get_next_message(_ignore)
# take!(messages_to_js)
# end


# @async begin
# sleep(5)
# for i in 1:10
# send_to_js(i)
# sleep(.3)
# end
# end


# @htl("""
# <script>
# const get_next_msg_from_julia = $(AbstractPlutoDingetjes.Display.with_js_link(get_next_message))

# let running = true
# let messages = async function* () {
# while(running) {
# yield await get_next_msg_from_julia()
# }
# }
# invalidation.then(() => {
# running = false
# })

# for await (const msg of messages()) {
# console.log(msg)
# }

# </script>
# """)

# end
👀 Reading hidden code
11.6 μs
1
let
c = Channel(1)
put!(c, 1)
take!(c)
end
👀 Reading hidden code
37.4 μs

👀 Reading hidden code
94.2 μs
link_from_julia (generic function with 1 method)
function link_from_julia()
messages_to_js = Channel()
running_ref = Ref{Bool}(true)

function get_next_message(_ignore)
if running_ref[]
# state[] *= "\nwaiting"
# @debug "waiting"
next = take!(messages_to_js)
# @info "done!" next
# state[] *= "\ndone $(next)"
if next === JSGeneratorFinish()
"__jsgen_stop"
else
next
end
else
"__jsgen_stop"
end
end

function stop_generator()
# @debug "stopping"
# state[] *= "\nstopping"
if running_ref[]
running_ref[] = false
# TODO if available
# TODO what if there are multiple clients connected?
put!(messages_to_js, JSGeneratorFinish())
# state[] *= "\nstopped"
end
end

js_generator = JSGenerator(
AbstractPlutoDingetjes.Display.with_js_link(get_next_message, stop_generator),
messages_to_js,
)
return js_generator
end
👀 Reading hidden code
2.1 ms
begin
struct JSGeneratorFinish end
struct JSGenerator
APDlink
channel
end

Base.put!(jsg::JSGenerator, msg) = put!(jsg.channel, msg)
function Base.show(io::IO, m::MIME"text/javascript", wjl::JSGenerator)
write(io, """(() => {
let messages = async function* () {
while(true) {
let next = await """)
show(io, m, wjl.APDlink)
write(io, """();
if(next === `__jsgen_stop`) return;
yield next;
}
};
let gen = messages();
invalidation.then(async () => {
console.log("stopping! 1")
gen.return()
console.log("stopping! 2")
});
return gen;
})()""")
end
end
👀 Reading hidden code
5.1 ms
state = Ref("")
👀 Reading hidden code
15.6 μs
# let
# link = link_from_julia()

# @async begin
# sleep(5)
# for i in 1:10
# put!(link, i)
# sleep(.3)
# end
# end

# @htl("""
# <script>
# for await (const msg of $(link)) {
# console.log(msg)
# }
# </script>
# """)
# end
👀 Reading hidden code
10.8 μs
state[] |> Text
👀 Reading hidden code
2.1 ms

👀 Reading hidden code
62.1 μs
Error message

syntax: extra token "THIS" after end of expression

BUT THIS ONLY WORKS FOR ONE CLIENT

WHCIH it should

but right now the messages go "randomly" to one of the clients
👀 Reading hidden code
---

👀 Reading hidden code
62.5 μs

👀 Reading hidden code
60.7 μs

👀 Reading hidden code
60.8 μs

👀 Reading hidden code
58.9 μs

👀 Reading hidden code
60.4 μs

👀 Reading hidden code
61.1 μs

👀 Reading hidden code
60.0 μs

👀 Reading hidden code
61.2 μs

👀 Reading hidden code
60.4 μs

👀 Reading hidden code
59.8 μs

👀 Reading hidden code
60.3 μs

👀 Reading hidden code
60.0 μs